package com.macro.mall.service.impl;

import com.github.pagehelper.PageHelper;
import com.macro.mall.mapper.UmsMemberLevelMapper;
import com.macro.mall.model.UmsMemberLevel;
import com.macro.mall.model.UmsMemberLevelExample;
import com.macro.mall.service.UmsMemberLevelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * 会员等级管理Service实现类
 * Created by macro on 2018/4/26.
 */
@Service
@Transactional
public class UmsMemberLevelServiceImpl implements UmsMemberLevelService{
    @Autowired
    private UmsMemberLevelMapper memberLevelMapper;
    @Override
    public List<UmsMemberLevel> list(Integer defaultStatus) {
        UmsMemberLevelExample example = new UmsMemberLevelExample();
        example.createCriteria().andDefaultStatusEqualTo(defaultStatus);
        return memberLevelMapper.selectByExample(example);
    }
    @Override
    public List<UmsMemberLevel> list(String keyword, Integer pageSize, Integer pageNum) {
        PageHelper.startPage(pageNum, pageSize);
        UmsMemberLevelExample example = new UmsMemberLevelExample();
        if (!StringUtils.isEmpty(keyword)) {
            example.createCriteria().andNameLike("%"+keyword+"%");
        }
        List<UmsMemberLevel> umsMemberLevels= memberLevelMapper.selectByExample(example);
        System.out.println(umsMemberLevels);
        return umsMemberLevels;
    }
    @Override
    public int update(UmsMemberLevel umsMemberLevel) {
        return memberLevelMapper.updateByPrimaryKeySelective(umsMemberLevel);
    }
    @Override
    public int delete(Long id) {
        return memberLevelMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int add(UmsMemberLevel umsMemberLevel) {
        umsMemberLevel.setPriviledgeFreeFreight(0);
        umsMemberLevel.setPriviledgeSignIn(0);
        umsMemberLevel.setPriviledgeBirthday(0);
        umsMemberLevel.setPriviledgeComment(0);
        umsMemberLevel.setPriviledgePromotion(0);
        umsMemberLevel.setPriviledgeMemberPrice(0);
        return memberLevelMapper.insert(umsMemberLevel);
    }
}
